package cn.ly.net.rpc;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 基于tcp协议的rpc远程调用server
 * @author liuyu
 *
 */

public class RPCServer {

	public static void main(String[] args) throws Exception {
		ServerSocket ss = new ServerSocket(8888);
		System.out.println("server starting ...");
		//监听，返回一个soeket对象
		Socket s = ss.accept();
		
		InputStream is = s.getInputStream();
		ObjectInputStream ois = new ObjectInputStream(is);
		Object[] o = (Object[])ois.readObject();
		HelloRpc r = (HelloRpc)o[0];
		String param = (String)o[1];
		String result = r.sayHello(param);
		OutputStream os = s.getOutputStream();
		os.write(result.getBytes());
		s.close();
	}
}
